package git.bds.nyc.admin.controller.gx;

import git.bds.nyc.admin.model.dto.OrderResultDTO;
import git.bds.nyc.admin.service.OrderManageService;
import git.bds.nyc.framework.excel.easyexcel.EasyExcelUtil;
import git.bds.nyc.result.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.time.LocalDateTime;
import java.util.List;

/**
 * @author 成大事
 * @since 2023/5/14 14:56
 */
@Api(tags = "订单管理")
@Validated
@RestController
@RequestMapping("/admin/order")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class OrderManageController {

    private final OrderManageService orderManageService;


    /**
     * 按日期导出订单列表
     *
     * @param startTime 开始时间
     * @param endTime   结束时间
     * @param type      类型
     * @return {@link R}<{@link Boolean}>
     */
    @SneakyThrows
    @ApiOperation("按日期导出订单列表")
    @GetMapping("/exportOrderListByDate/{type}/{startTime}/{endTime}")
    public void exportOrderListByDate(
            @PathVariable("type") int type,
            @PathVariable("startTime")LocalDateTime startTime,
            @PathVariable("endTime")LocalDateTime endTime,
            HttpServletResponse response
    ){
        List<OrderResultDTO> list = orderManageService.exportOrderListByDate(type, startTime, endTime);
        EasyExcelUtil.writeWithSheetsWeb(response,"order",OrderResultDTO.class,list);
    }
}
